package com.dx_society.controller;

import com.dx_society.dto.Result;
import com.dx_society.dto.UserDetailDTO;
import com.dx_society.service.UserDetailService;
import com.dx_society.service.UserService;
import com.dx_society.utils.UserHolder;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;
    @Resource
    private UserDetailService userDetailService;


    /**
     * 登录功能
     */
    @PostMapping("/login")
    public Result login(@RequestParam Long userId, @RequestParam String passRsa){
        return userService.login(userId, passRsa);
    }

    /**
     * 注册功能
     */
    @PostMapping("/register")
    public Result register(@RequestParam Long userId, @RequestParam String username, @RequestParam String passRsa){
        return userService.register(userId,username,passRsa);
    }

    /**
     * 获取用户详情
     * @return 用户详情
     */
    @GetMapping("/detail")
    public Result getUserDetail(){
        return userDetailService.queryUserDetail();
    }

    /**
     * 设置用户详情
     * @param userDetailDTO 用户详情DTO
     * @return 结果信息
     */
    @PostMapping("/detail/set")
    public Result setUserDetail(@RequestBody UserDetailDTO userDetailDTO){
        return userDetailService.setUserDetail(userDetailDTO);
    }

    @GetMapping("/myId")
    public Result getMyId(){
        Long userId;
        try {
            userId = UserHolder.getUser().getUserid();
        } catch (Exception e) {
            return Result.fail("用户未登录");
        }

        return Result.ok(userId);
    }


/*
  ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  管理员相关
 */
//    /**
//     * 获取用户列表
//     * @param current 当前页
//     * @param size 每页大小
//     * @return 用户列表
//     */
//    @GetMapping("/list")
//    public Result getUserList(@RequestParam(value = "current", defaultValue = "1") Integer current,
//                              @RequestParam(value = "size", defaultValue = "10") Integer size){
//        return userService.queryUserList(current, size);
//    }
//
//    /**
//     * 修改用户权限
//     *
//     * @param userId 用户id
//     * @param role 权限
//     * @return 结果信息
//     */
//    @PostMapping("/permission/set")
//    public Result setUserPermission(@RequestParam("userId") Long userId,
//                                    @RequestParam("role") String role){
//        return userService.setUserPermission(userId,role);
//    }
//
//    /**
//     * 删除指定用户
//     *
//     * @param userId 用户id
//     * @return 结果信息
//     */
//    @PostMapping("/delete")
//    public Result deleteUser(@RequestParam("userId") Long userId){
//        return userService.deleteUser(userId);
//    }
//
//
//    /**
//     * 获取页面uv
//     *
//     * @param date 日期 格式为 yyyy-MM-dd
//     * @return uv
//     */
//    @GetMapping("/uv")
//    public Result getUV(@RequestParam("date") String date){
//        return userService.getUV(date);
//    }
}
